/**
 * Javascript file for handling the configfile.
 * It will be filled on load and written while closing the app.
 * 
 * @author Erwin Goossen
*/

/**
 * Create a config object
 * @param {Object} firstRun
 * @param {Object} sqlFile
 */
function createConfig(firstRun,sqlFile){
	this.firstRun 	= 1;
	this.sqlFile 	= 'CollectionDump.sql';
	this.excist 	= false;
	this.lyrics 	= false;
	this.concert 	= true;
	this.ip 		= '0.0.0.0';
	this.location 	= '';
	this.country 	= '';
	this.getXML 	= getXML;
	this.showConfig = showConfig;
	this.saveConfig = saveConfig;
}

/**
 * Get the xml for saving in a file
 */	
function getXML(){
	with (this) return  '<?xml version="1.0" encoding="UTF-8"?><configuration>' +
						'<sqlFile>' + sqlFile + '</sqlFile>' +
						'<firstRun>' + firstRun + '</firstRun>' +
						'<lyrics>' + lyrics + '</lyrics>' +
						'<concert>' + concert + '</concert>' +
						'<ip>' + ip + '</ip>' +
						'<location>' + location + '</location>' +
						'<country>' + country + '</country>' +
						'</configuration>';
}

/**
 * Putting the config elements into html values in configuration window
 */
function showConfig(){
	var bool = false;
	with (this) bool = lyrics;
	if (bool=='true') {
		$('#checkLyrics').attr('checked', true);
	}
	with (this) bool = concert;
	if (bool=='true') {
		$('#checkConcert').attr('checked', true);
	}
	with (this) $('#txtSQL').val(sqlFile);
	with (this) $('#txtIP').val(ip);
	with (this) $('#txtLocation').val(location);
	with (this) $('#txtCountry').val(country);
}

/**
 * Writing the html values to config elements
 */
function saveConfig() {
	with (this) lyrics   = $('#checkLyrics').attr('checked') ? 'true' : 'false';
	with (this) concert  = $('#checkConcert').attr('checked') ? 'true' : 'false';
	with (this) ip       = $('#txtIP').val();
	with (this) location = $('#txtLocation').val();
	with (this) country  = $('#txtCountry').val();
}
	
	
